<%@page import="mall.bean.Category"%>
<%@page import="java.util.List"%>
<%@page import="mall.service.impl.CategoryServiceImpl"%>
<%@page import="mall.service.CategoryService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/scrollbar.css"/>
		<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.min.css"/>
	</head>
	<body>
	
		<%
		// 要查询的页码及每页行数
		int pageSize = 8;
		int pageNo = 1;
		String strPageNo = request.getParameter("pageNo");
		if(strPageNo != null)
			pageNo = Integer.parseInt(strPageNo);
		CategoryService service = new CategoryServiceImpl();
		// 查当前页数据
		List<Category> list = service.findPageList(pageNo, pageSize);
		// 查总行数
		long count = service.count();
		// 计算总页数
		long totalPages = ((count-1) / pageSize) + 1;
		// 上一页的页码?
		long prev = pageNo > 1 ? pageNo - 1 : 1;
		// 下一页的页码?
		long next = pageNo < totalPages ? pageNo + 1 : totalPages;
		%>
		<div class="container">
		<ol class="breadcrumb">
			  <li><a href="#">首页</a></li>
			  <li><a href="#">商品</a></li>
			  <li class="active">商品分类列表</li>
		</ol>
		<table class="table table-hover table-bordered">
			<thead>
				<tr>
					<th>编号</th>
					<th>分类名称</th>
					<th>级别</th>
					<th>排序值</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<%
				for(Category c : list)
				{
				%>
				<tr>
					<td><%=c.getCid() %></td>
					<td><%=c.getName() %></td>
					<td><%=c.getLevel() %></td>
					<td><%=c.getSort() %></td>
					<td>
						<a href="category-edit.jsp?cid=<%=c.getCid() %>" class="btn btn-info btn-xs">编辑</a>
						<a href="category-del.jsp?cid=<%=c.getCid() %>" onclick="return confirm('确定要删除该行数据吗?')" class="btn btn-danger btn-xs">删除</a>
					</td>
				</tr>
				<%
				}
				%>
			</tbody>
		</table>
		<nav>
		  <ul class="pager">
		    <li><a href="category-list.jsp?pageNo=<%=prev%>">上一页</a></li>
		    <li><a href="category-list.jsp?pageNo=<%=next%>">下一页</a></li>
		  </ul>
		</nav>
		</div>
	</body>
</html>
    